package com.jacksonling.controller;

import com.jacksonling.pojo.PageResult;
import com.jacksonling.pojo.Result;
import com.jacksonling.pojo.Student;
import com.jacksonling.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    /**
     * 分页查询（学员列标查询）
     */
    @GetMapping
    public Result Page(String name,
                       Integer degree,
                       Integer clazzId,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult pageResult = studentService.page(name, degree, clazzId, page, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 新增学生
     */
    @PostMapping
    public Result save(@RequestBody Student student){
        studentService.save(student);
        return Result.success();
    }

    /**
     * 根据 ID 查询学生
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Student student = studentService.getById(id);
        return Result.success(student);
    }

    /**
     * 修改学生信息
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }

    /**
     * 批量删除学生
     */
    @DeleteMapping("/{id}")
    public Result deleteBatch(@PathVariable List<Integer> id){
        studentService.deleteBatch(id);
        return Result.success();
    }

    /**
     * 违纪处理接口
     */
    @PutMapping("/violation/{id}/{score}")
    public Result violationHandle(@PathVariable Integer id, @PathVariable Short score){
        studentService.violationHandle(id, score);
        return Result.success();
    }
}
